package cn.edu.scau.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Formula;

@Entity
@Table(name = "comment")
public class Comment {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "comment_id")
	private Integer commentId;

	@Column(name = "commentor_id", nullable = false)
	private Integer commentorId;

	@Formula("(select u.nickName from user u where u.user_id=commentor_id)")
	private String commentor;

	@Column(name = "content", nullable = false, length = 256)
	private String content;

	@Column(name = "time", nullable = false)
	private String time;

	@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
	@JoinTable(name = "comment_reply", joinColumns = @JoinColumn(name = "comment_id", referencedColumnName = "comment_id") , inverseJoinColumns = @JoinColumn(name = "reply_id", referencedColumnName = "reply_id", unique = true) )
	private Set<Reply> replies = new HashSet<Reply>();

	public Integer getCommentId() {
		return commentId;
	}

	public void setCommentId(Integer commentId) {
		this.commentId = commentId;
	}

	public Integer getCommentorId() {
		return commentorId;
	}

	public void setCommentorId(Integer commentorId) {
		this.commentorId = commentorId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public Set<Reply> getReplies() {
		return replies;
	}

	public void setReplies(Set<Reply> replies) {
		this.replies = replies;
	}

	public String getCommentor() {
		return commentor;
	}

	public void setCommentor(String commentor) {
		this.commentor = commentor;
	}

}